package com.beauty.dressing.module.market.holder;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.beauty.dressing.R;
import com.beauty.dressing.common.base.BaseRecyclerViewHolder;
import com.beauty.dressing.common.bean.BaseBean;
import com.beauty.dressing.common.bean.LeaseOrderResp;
import com.beauty.dressing.common.interfaces.OnRecyclerViewItemListener;

/**
 * @author xutingz
 * @E-mail xutz@xianlanba.com
 * @date 2018/5/27
 */
public class WriteOrderHeaderHolder extends BaseRecyclerViewHolder<BaseBean> implements View.OnClickListener {
    private RadioButton market_tab, home_tab;
    TextView user_address_txt, user_phone_txt, user_name_txt;
    TextView goods_total_amount_txt, the_freight_txt, order_total_amount_txt, address_status;
    LinearLayout user_address_ll;
    LeaseOrderResp mBean;
    private OnRecyclerViewItemListener onRecyclerViewItemListener;

    public WriteOrderHeaderHolder(Context context, LayoutInflater inflater, ViewGroup viewGroup) {
        super(R.layout.write_order_header, context, inflater, viewGroup);
    }

    @Override
    public void findView() {
        home_tab = itemView.findViewById(R.id.home_tab);
        market_tab = itemView.findViewById(R.id.market_tab);
        user_address_txt = itemView.findViewById(R.id.user_address_txt);
        user_phone_txt = itemView.findViewById(R.id.user_phone_txt);
        user_name_txt = itemView.findViewById(R.id.user_name_txt);
        goods_total_amount_txt = itemView.findViewById(R.id.goods_total_amount_txt);
        the_freight_txt = itemView.findViewById(R.id.the_freight_txt);
        order_total_amount_txt = itemView.findViewById(R.id.order_total_amount_txt);
        user_address_ll = itemView.findViewById(R.id.user_address_ll);
        address_status = itemView.findViewById(R.id.address_status);
        home_tab.setOnClickListener(this);
        market_tab.setOnClickListener(this);
        user_address_ll.setOnClickListener(this);
    }

    @Override
    public void bindData(BaseBean bean, int position) {
        Log.e(TAG, bean.toString());
    }

    @Override
    public void bindData(BaseBean bean) {
        Log.e(TAG, bean.toString());
        if (bean instanceof LeaseOrderResp) {
            this.mBean = (LeaseOrderResp) bean;
            double goods_total = Double.valueOf(((LeaseOrderResp) bean).goods.price)
                    + Double.valueOf(((LeaseOrderResp) bean).goods.deposit);
            address_status.setVisibility(((LeaseOrderResp) bean).defaAddress.getStatus() == 0 ? View.INVISIBLE : View.VISIBLE);
            user_address_txt.setText(((LeaseOrderResp) bean).defaAddress.getAddress());
            user_phone_txt.setText(((LeaseOrderResp) bean).defaAddress.getPhone());
            user_name_txt.setText(((LeaseOrderResp) bean).defaAddress.getName());
            goods_total_amount_txt.setText("¥" + goods_total);//商品总金额
            the_freight_txt.setText("¥" + ((LeaseOrderResp) bean).goods.leasePostage);//运费
            Double order_total = Double.valueOf(((LeaseOrderResp) bean).goods.price)
                    + Double.valueOf(((LeaseOrderResp) bean).goods.leasePostage)
                    + Double.valueOf(((LeaseOrderResp) bean).goods.deposit);
            order_total_amount_txt.setText("¥" + order_total);//订单总额
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.home_tab:
                user_address_ll.setVisibility(View.VISIBLE);
                break;
            case R.id.market_tab:
                user_address_ll.setVisibility(View.GONE);
                break;
            case R.id.user_address_ll:
                onRecyclerViewItemListener.onItemViewOnClick(R.id.user_address_ll, 0);
                break;
        }
    }

    public void setOnRecyclerViewItemListener(OnRecyclerViewItemListener onRecyclerViewItemListener) {
        this.onRecyclerViewItemListener = onRecyclerViewItemListener;
    }
}
